package com.asa.chart;

import com.asa.hutils.MathHUtils;
import com.asa.jihe.utils.Euclid;
import com.asa.jihe.utils.Point;

/**
 * 	二维空间上的一个坐标变换
 * 
 * 
 * @author Administrator
 *
 */
public class Transform2D {
	

	
	
	/**
	 * 	二维坐标平面上，某个点绕着另一个点进行旋转，求旋转后的点的坐标值
	 * @return
	 */
	
	public static double[] rotate(double[] xy1,double[] xy2,double alpha) {
		
		double x1= xy1[0];
		double y1= xy1[1];
		double x2= xy2[0];
		double y2= xy2[1];
		
		double result_x1 = (x1 - x2)*Math.cos(alpha) + (y1 - y2)*Math.sin(alpha) + x2;
		double result_y1 = (y1 - y2)*Math.cos(alpha) - (x1 - x2)*Math.sin(alpha) + y2;

		double[] result = {result_x1,result_y1};

		return result;
	}
	
	
	/**
	 * 	求两个点的中点
	 * @param xy1
	 * @param xy2
	 * @return
	 */
	public static double[] midpoint(double[] xy1,double[] xy2) {
		
		double x1= xy1[0];
		double y1= xy1[1];
		double x2= xy2[0];
		double y2= xy2[1];
		double result_x1 = (x1+x2)/2.0;
		double result_y1 = (y1+y2)/2.0;
		double[] result = {result_x1 ,result_y1};

		return result;
	}
	
	
	
	/**
	 * 移动平面上的点
	 * @param xy1
	 * @param x2
	 * @param y2
	 * @return 点坐标变更后的坐标
	 */
	public static double[] move(double[] xy1,double x2,double y2) {
		
		double x1= xy1[0];
		double y1= xy1[1];
		double result_x1 = x1+x2;
		double result_y1 = y1+y2;
		double[] result = {result_x1 ,result_y1};

		return result;
	}
	
	
	
	/**
	 * 反射
	 * 没有测试
	 * @param xy1
	 * @param x2
	 * @param y2
	 * @return 点坐标变更后的坐标
	 */
	public static double[][] reflection(double[] xy1) {
		
		double x1= xy1[0];
		double y1= xy1[1];
		
		double [][] asa = {{-1,0},{0,1}};
		
		
		double[][] asb= {xy1};
		asb = MathHUtils.zhuanzhi(asb);
		double[][] result = MathHUtils.chenfa(asa, asb);
		
		
		MathHUtils.print(result);

		return result;
	}
	
	
	
	
	
	/**
	 * 平移
	 * 一般的平移思路是各个坐标加上点什么
	 * 
	 * 用乘法表示的
	 */
	public static double[][] move2(double[] xy1,double move2x,double move2y) {
		
		double [][] asa = MathHUtils.getI(3);
		asa[0][2]=move2x;
		asa[1][2]=move2y;

		
		double[][] asb= new double[1][3];
		for (int i = 0; i < xy1.length; i++) {
			asb[0][i] = xy1[i];
		}
		asb[0][2] = 1;
		
		
		asb = MathHUtils.zhuanzhi(asb);
		double[][] result = MathHUtils.chenfa(asa, asb);
		
		
		MathHUtils.print(result);

		return result;
	}
	
	
	
	
	/**
	 * 重心
	 * 三角形
	 * (x,y) = aA+bB+cC		其中ABC是指的点(x,y)
	 * a+b+c=1
	 * 
	 * 问题是如何计算
	 * 
	 */
	
	public static double[] asa(double[] A,double[] B,double[] C) {
		
		
		
		
//		Point a = Euclid.toPoint(A);
//		Point b = Euclid.toPoint(B);
//		Point c = Euclid.toPoint(C);
//		Point xiangliang1 = Euclid.xiangliang(b, a);
//		Point xiangliang2 = Euclid.xiangliang(c, a);
//		
//		double chacheng = Euclid.chacheng(xiangliang1, xiangliang2);
		
		
		
		
		return null;
		
		
		
		
		
		
	}
	
	
	
	
	
	
	
	
	
	
	public static void main(String[] args) {

//		reflection(new double[]{0,1});
		
		
		move2(new double[] {1,1}, 1, 1);
		
	}



	
	
	
	
	
	

}
